<?php 
/**
 * 个人中心控制器
 */
class MemberController extends CommonController{
	public function Index(){
		if(isset($_SESSION['uid'])){
			$info = M('hd_user')->where("uid={$_SESSION['uid']}")->find();
			if($info['answer']){
				$adopt = ($info['accept']/$info['answer'])*100;
				$adopt = round($adopt);
			}else{
				$adopt = 0;
			}
			$info['adopt'] = $adopt;
			$this->assign('info',$info);
		}
//		我的问题
		$myAskArr = M('hd_ask')->query("SELECT * FROM hd_ask AS a JOIN hd_category AS c ON a.cid=c.cid where uid={$_SESSION['uid']} limit 5" );
		$num = M('hd_ask')->where("uid={$_SESSION['uid']}")->field("count(*) as num")->find();
		foreach ($myAskArr as $k => $v) {
			$myAskArr[$k]['time'] = date("Y-m-d",$v['time']);
		}
		$myAskArr['num'] = $num['num'];
		$this->assign('myAskArr', $myAskArr);
//		我的回答
		$myAnsweArr = M('hd_ask')->query("select ak.content as wenti,aw.content as huida,title,aw.time from hd_category as u join hd_ask as ak on u.cid=ak.cid join hd_answer as aw on ak.asid=aw.asid where aw.uid={$_SESSION['uid']} limit 5" );
		$num = M('hd_answer')->where("uid={$_SESSION['uid']}")->field("count(*) as num")->find();
		foreach ($myAnsweArr as $k => $v) {
			$myAnsweArr[$k]['time'] = date("Y-m-d",$v['time']);
		}
		$myAnsweArr['num'] = $num['num'];
		$this->assign('myAnsweArr', $myAnsweArr);

		$this->leftCate();
		$this->topCate();
		$this->display();
	}
	public function myask(){
		$this->display();
	}
	
	
}


